package com.otojob.service.impl;

import com.otojob.dto.PageDto;
import com.otojob.entity.JobList;
import com.otojob.mapper.JobListMapper;
import com.otojob.service.JobListService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.otojob.utils.Results;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author TingFeng
 * @since 2022-03-28
 */
@Slf4j
@Service
public class JobListServiceImpl extends ServiceImpl<JobListMapper, JobList> implements JobListService {

    @Resource
    private JobListMapper jobListMapper;
    /**
     * 工作分类
     * @return
     */
    @Override
    public Results findAllJobList(PageDto pageDto) {
        int numPage=pageDto.getPageNum();
        int numSize=pageDto.getPageSize();

        List<JobList> list = jobListMapper.findAllJobList((numPage - 1) * numSize, numSize);

        int totals = list.size();

        int pages = (int) Math.ceil(totals/numSize);

        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("numPage",numPage);
        map.put("numSize",numSize);
        map.put("totals",totals);
        map.put("pages",pages);
        map.put("jobList",list);

        return Results.ok().data(map);
    }

    @Override
    public Results addJobList(JobList job) {
        jobListMapper.addJobList(job);
        return Results.ok();
    }

    @Override
    public Results findJobList(PageDto pageDto,String condition) {
        int numPage=pageDto.getPageNum();
        int numSize=pageDto.getPageSize();
        List<JobList> list = jobListMapper.findJobList((numPage - 1) * numSize, numSize, condition);
        int totals = list.size();
        int pages = (int) Math.ceil(totals/numSize);
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("numPage",numPage);
        map.put("numSize",numSize);
        map.put("totals",totals);
        map.put("pages",pages);
        map.put("jobList",list);
        return Results.ok().data(map);

    }
}
